{extend name="../../admin/view/main"}

{block name="style"}{include file='eduenroll/form-style'}{/block}

{block name='content'}
<style>
    .upload-image-box {
        width: 130px;
        height: 110px;
        border: 1px solid rgba(125, 125, 125, .1);
        background-size: cover;
    }
    .upload-file-box {
        width: 80px;
        height: 50px;
        border: 1px solid rgba(125, 125, 125, .1);
        background-size: cover;
    }


</style>
<div id="infoFormEditor" class="layui-clear nowrap padding-bottom-30">
    <div class="layui-card news-right">
        <div class="layui-card-body">
            <!--<form onsubmit="return false" data-auto="true" action="{:request()->url()}" method="post" class='layui-form layui-card' autocomplete="off">-->
            <form class="layui-form padding-20" role="form" name="infoForm" onsubmit="return false">
                <style>.layui-form-select dl { max-height:120px; }</style>
                <table width="100%">
                    <tr>
                        <td style="padding-right:20px;">
                            <label class="layui-form-item relative block">
                                <span class="color-green">班级名称</span>
                                <select name="room_id" size="5" class="layui-select" lay-filter="demo">
                                    <option>--请选择班级名称--</option>
                                    {foreach $groups as $key=>$vo}
                                        {if $vo.id eq $enroll.room_id}
                                        <option selected value="{$vo.id}">{$vo.name}</option>
                                        {else}
                                        <option value="{$vo.id}">{$vo.name}</option>
                                        {/if}
                                    {/foreach}
                                </select>
                            </label>
                        </td>
                        <td>
                            <label class="layui-form-item relative block">
                                <span class="color-green">座位号</span>
                                <input maxlength="32" value="{$enroll.seat_no}" required placeholder="请在这里输入座位号" name='seat_no' class="layui-input">
                            </label>
                        </td>
                    </tr>
                </table>
                <div class="layui-form-item text-center padding-top-30">
                    <input name="id" value="{$enroll.id}" type="hidden">
                    <button ng-click="submit()" type="button" class="layui-btn">保存信息</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div name="annex-template" style="display: none;">
    <div class="item" file="__URL__">
        <a target="_blank" href="__URL__">__TITLE__</a>
        <span class="font-s20 fa fa-trash"></span>
    </div>
</div>
{/block}


{block name='script'}
<script>window.form.render()</script>
<script>

    layui.use(['layer', 'jquery', 'form'], function () {
        layui.form.on('select(demo)', function(data){
            let positions = getClassPositions(data.value);
            let html = '<option>--请选择工种--</option>';
            for(let i=0; i<positions.length; i++){
                html += '<optgroup label="'+positions[i].name+'">'+positions[i].name+'</optgroup>';

                for(let j=0; j<positions[i]['sub'].length; j++) {
                    html += '<option value="' + positions[i]['sub'][j]['id'] + '">' + positions[i]['sub'][j]['name'] + '</option>'
                }
            }
            $("select[name=position_id]").html(html);
            layui.form.render();
        });
        layui.form.on('radio(GenderRadio)', function(data){
            $("input[name=gender]").val(data.value);
        });
    });

    laydate.render({
        elem: '#occur_time' //指定元素
    });

        require(['angular', 'ckeditor'], function () {

            /*layui.use(['form'], function () {
                var form = layui.form;
            });*/

        var editor;
        var $form = $('form[name="infoForm"]');
        var $vali = $form.vali().data('validate');

        var app = angular.module("infoFormEditor", []).run(callback);
        angular.bootstrap(document.getElementById(app.name), [app.name]);

        function callback($rootScope) {
            $rootScope.list = [];
            $rootScope.item = {};
            $.form.load('{:request()->url()}', {output: 'json'}, 'get', function (ret) {
                console.log(typeof ret);
                console.log(ret);
                return $rootScope.$apply(function () {
                    apply(ret.data || {});
                }), false;
            });
                function apply(qiye) {
                    if(qiye.id==undefined) qiye = {
                        name: '', phone: '', contacts: '',intro:'',
                        addr: '', avatar: '__ROOT__/static/theme/img/image.png'
                    };
                    $rootScope.item = qiye;
                    $('.layui-card-body.layui-hide').removeClass('layui-hide');
                    $rootScope.item.style = "background-image:url('" + $rootScope.item.avatar + "')";
                }
            $rootScope.setItemValue = function (name, value) {
                $rootScope.item[name] = value;
                $rootScope.item.style = "background-image:url('" + $rootScope.item.avatar + "')";
            };

            $rootScope.upItem = function (index, $event) {
                $event.stopPropagation();
                var tmp = [], cur = $rootScope.list[index];
                if (index < 1) return false;
                for (var i in $rootScope.list) {
                    (parseInt(i) === parseInt(index) - 1) && tmp.push(cur);
                    (parseInt(i) !== parseInt(index)) && tmp.push($rootScope.list[i]);
                }
                apply(tmp);
            };
            $rootScope.dnItem = function (index, $event) {
                $event.stopPropagation();
                var tmp = [], cur = $rootScope.list[index];
                if (index > $rootScope.list.length - 2) return false;
                for (var i in $rootScope.list) {
                    (parseInt(i) !== parseInt(index)) && tmp.push($rootScope.list[i]);
                    (parseInt(i) === parseInt(index) + 1) && tmp.push(cur);
                }
                apply(tmp);
            };
            $rootScope.delItem = function (index, $event) {
                $event.stopPropagation();
                var list = $rootScope.list, temp = [];
                for (var i in list) (parseInt(i) !== parseInt(index)) && temp.push(list[i]);
                apply(temp);
            };
            $rootScope.submit = function () {
                $vali.checkAllInput();
                if ($form.find('.validate-error').size() > 0) {
                    return $.msg.tips('表单验证不成功，请输入需要的内容！');
                }
                var data = {
                    id: $("input[name='id']").val(),
                    room_no: $("select[name='room_id']").find("option:selected").text(),
                    room_id: $("select[name='room_id']").val(),
                    seat_no: $("input[name='seat_no']").val(),
                };
                $.form.load('{:request()->url()}', {data: data}, "post");
            };
        }
    });
</script>




{/block}